package com.cmy.lesson03;

import com.cmy.lesson2.utils.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

public class TestDelete {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement pst = null;
        try {
            conn = JdbcUtils.getConnection();
            //=================替换区域==========================
            //与statement 的区别
            //先搭建sql框架(预编译sql),并使用?充当占位符,
            String sql  = "delete from `users` where id = ?";
            pst  = conn.prepareStatement(sql);//预编译sql
            //手动将给占位符赋值 (第几个参数,值)
            pst.setInt(1,4);
            //执行 这里不在传参(预编译过了)
            int i = pst.executeUpdate();
            if (i>0){
                System.out.println("删除成功");
            }
            //===================================================
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            JdbcUtils.release(conn,pst,null);
        }
    }
}

    